<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="root" value="${pageContext.request.contextPath}"/>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	
	<script type="text/javascript">
		function _addInput(){
			//alert();
			//当用户点击按钮的时候，添加一个input输入框
			//input输入框添加在那个位置
			//获取div的位置
			var _add = document.getElementById("_add");
			
			//创建input标签
			var _input = document.createElement("input");
			
			//设置input输入框的属性和值
			_input.setAttribute("type", "file");
			_input.setAttribute("name", "upload");
			
			//将input添加到div中
			_add.appendChild(_input);
			
			
			
			//创建一个删除按钮
			var _delete = document.createElement("input");
			_delete.setAttribute("type", "button");
			_delete.setAttribute("value", "删除");
			_add.appendChild(_delete);
			//删除动作，调用父标签的removeChild()方法来删除子元素
			//删除的动作要在点击事件发生时去做
			_delete.onclick = function (){
				//获取父标签
				var _f = this.parentNode;
				//获取要删除的节点（元素）：_input:当前元素的前一个元素     br： 当前元素的前一个元素  
				var _p = this.previousSibling;
				var _n = this.nextSibling;
				_f.removeChild(_p);
				_f.removeChild(_n);
				//删除自身
				_f.removeChild(this);
				
			};
			
			//添加一个换行符
			var _br = document.createElement("br");
			_add.appendChild(_br);
			
		}
	
	</script>
	
  </head>
  
  <body>
  <input type="button" value="添加文件" onclick="_addInput();">
  	<form action="${root}/upload3" method="post" enctype="multipart/form-data">
  		文件描述：<input type="text" name="desc"></br>
  		 选择要上传的文件：<input type="file" name="upload"></br>
  		 <!-- div是用来标记input输入框要插入的位置 -->
  		 <div id="_add"></div>
  	 <input type="submit" value="确认上传"></br>
  	</form>
  </body>
</html>
